#include "MeltOkDialog.h"
#include "../../../model/static/StaticItem.h"
#include "../../../model/proxy/UserProxy.h"
#include "../../../model/proxy/ItemProxy.h"
#include "../../../net/NetController.h"

MeltOkDialog::MeltOkDialog(void)
	:mGetEnergy(NULL),mTotalEnergy(NULL)
{
}

MeltOkDialog::~MeltOkDialog(void)
{
	CC_SAFE_RELEASE(mGetEnergy);
	CC_SAFE_RELEASE(mTotalEnergy);
}

bool MeltOkDialog::init()
{
	return true;
}

SEL_MenuHandler MeltOkDialog::onResolveCCBCCMenuItemSelector(CCObject * pTarget, CCString * pSelectorName )
{
	return NULL;
}

SEL_CCControlHandler MeltOkDialog::onResolveCCBCCControlSelector( CCObject * pTarget, CCString * pSelectorName )
{
	CCB_SELECTORRESOLVER_CCCONTROL_GLUE(this, "onOkBtnClick", MeltOkDialog::onOkBtnClick);
	CCB_SELECTORRESOLVER_CCCONTROL_GLUE(this, "onCanselBtnClick", MeltOkDialog::onCanselBtnClick);
	return NULL;
}

bool MeltOkDialog::onAssignCCBMemberVariable( CCObject * pTarget, CCString * pMemberVariableName, CCNode * pNode )
{
	CCB_MEMBERVARIABLEASSIGNER_GLUE(this, "mGetEnergy", CCLabelTTF *, this->mGetEnergy);
	CCB_MEMBERVARIABLEASSIGNER_GLUE(this, "mTotalEnergy", CCLabelTTF *, this->mTotalEnergy);
	return false;
}

void MeltOkDialog::onNodeLoaded( CCNode * pNode, CCNodeLoader * pNodeLoader )
{

}

void MeltOkDialog::onEnter()
{
	ModelDialog::onEnter();
}

void MeltOkDialog::onExit()
{
	ModelDialog::onExit();
}

void MeltOkDialog::refresh()
{
	mGetEnergy->setString(itos(getMeltCost()));
	mTotalEnergy->setString(itos(UserProxy::getSingletonPtr()->userVO.rEnergy));
}

void MeltOkDialog::_onNotification( CCObject* object )
{
	
}

void MeltOkDialog::onOkBtnClick( CCObject * pSender, CCControlEvent pCCControlEvent )
{
	EquipInfo* equipInfo = (EquipInfo*)mData;
	vector<int>& meltList = ItemProxy::getSingletonPtr()->mSelectList;
	NetController::getSingletonPtr()->fusionEquipage(meltList);
	close();
}

void MeltOkDialog::onCanselBtnClick( CCObject * pSender, CCControlEvent pCCControlEvent )
{
	close();
}

void MeltOkDialog::touchScreen()
{
	close();
}

int MeltOkDialog::getMeltCost()
{
	int cost = 0;
	vector<int>& selectlList = ItemProxy::getSingletonPtr()->mSelectList;
	for (int i = 0; i < selectlList.size(); i++)
	{
		EquipInfo* equipInfo = ItemProxy::getSingletonPtr()->getEquip(selectlList[i]);
		EquipStatic* equipStatic = StaticItem::getSingletonPtr()->getEquipInfo(equipInfo->id);
		//cost += equipStatic->supply_exp;
		cost += 10;
	}
	return cost;
}
